package org.zzk.dao;

import com.google.gson.JsonObject;
import lombok.Data;

@Data
public class Piece {
    public enum PieceType {
        GENERAL,    // 将/帅
        ADVISOR,    // 士
        ELEPHANT,   // 象
        HORSE,      // 马
        CHARIOT,    // 车
        CANNON,     // 炮
        SOLDIER     // 兵/卒
    }

    private final PieceType type;
    private final boolean isRed; // 红方为true，黑方为false

    public Piece(PieceType type, boolean red) {
        this.type = type;
        this.isRed = red;
    }

    public JsonObject toJson() {
        JsonObject json = new JsonObject();
        json.addProperty("type", type.toString());
        json.addProperty("isRed", isRed);
        return json;
    }

    public String getChineseName() {
        String res = "";
        // 根据类型和颜色返回对应的中文名
        switch (type) {
            case GENERAL:
                res = this.isRed ? "帅" : "将";
                break;
            case ADVISOR:
                res = "士";
                break;
            case ELEPHANT:
                res = this.isRed ? "相" : "象";
                break;
            case HORSE:
                res = "马";
                break;
            case CHARIOT:
                res = "车";
                break;
            case CANNON:
                res = "炮";
                break;
            case SOLDIER:
                res = this.isRed ? "兵" : "卒";
                break;
            default:
                res = "未知";
                break;
        }
        return res;
    }
}